package com.test.dababy.dababy_00_analytics.dababydata_sdk.dababytask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababybeans.DababyASRequestPms;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyhttp.DababyASReqstManger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababylogger.DababyASLger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyservices.DababyASHdwIfo;
import com.test.dababy.dababy_00_path.Paths_dababy;
import com.test.dababy.dababy_00_utils.DababyUtil;

import java.util.function.Supplier;


public class DababyASDevcHadwTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceHardwareTask";

    private final String mTaskId;
    private final Context mContext;

    public String pYu5="";
    public double pSi7=0.5093597573415378;
    public boolean oHgk=true;
    public double gQ43=0.6252241577213264;
    public String u3xV="";

    public void yzsVr(){
        new Thread(() -> {
            try {
                setpYu5(String.valueOf(pSi7)+oHgk);
                if (TextUtils.isEmpty(pYu5)) setU3xV(String.valueOf(gQ43));
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setpYu5(String pYu5) {
        this.pYu5 = pYu5;
    }

    public void setpSi7(double pSi7) {
        this.pSi7 = pSi7;
    }

    public void setoHgk(boolean oHgk) {
        this.oHgk = oHgk;
    }

    public void setgQ43(double gQ43) {
        this.gQ43 = gQ43;
    }

    public void setU3xV(String u3xV) {
        this.u3xV = u3xV;
    }

    public DababyASDevcHadwTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get()  {
        // 日志标记
        DababyASLger.d_dababy(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(Paths_dababy.PATH_HARDWARE)) {
            return mTaskId + "";
        }

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE)) {
            infoBeans = DababyASHdwIfo.getZipString_dababy(mContext);

        } else {
            // 日志标记
            DababyASLger.d_dababy(TAG, "获取硬件信息出错：没有 READ_PHONE_STATE 权限");
            return mTaskId + "";
        }

        DababyASRequestPms netParams = new DababyASRequestPms();
        netParams.setDHG_dababy(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_dababy(Paths_dababy.PATH_HARDWARE);

        yzsVr();

        // 上报请求
        String url = DababyUtil.getCommonPath_dababy();
        new DababyASReqstManger.Builder_dababy().setReqId_dababy(this.mTaskId).setUrl_dababy(url).setBody_dababy(result).build_dababy().doPostRqst_dababy();

        return mTaskId + "";
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }
}
